/* eslint-disable no-unused-vars */
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useState, useEffect } from 'react';
import Cookies from 'js-cookie';
import RequestApi from '@/utils/request';
import css from './index.scss';

/**
 * @description 管理员打印的重庆市停车备案登记证
 */
function Print(props) {
	const { id } = props;
	const [data, setData] = useState();
	const distinctId = Cookies.get('distinctId');
	const body = {
		address: null,
		districtId: distinctId,
		isInImportantBusinessCircle: null,
		manageOrgName: null,
		name: null,
		parkLevel: null,
		parkLotType: null,
		propertyOrgName: null,
		status: null,
	};
	useEffect(() => {
		RequestApi.connection('post', `parkLot/getManageParkList`, body).then((response) => {
			const allData = response.data;
			for (let i = 0; i < allData.length; i += 1) {
				if (allData[i].id === id) {
					const getData = allData[i];
					const date = getData.createdAt.split(' ')[0].split('-');
					const newData = {
						recordNo: getData.recordNo,
						name: getData.name,
						address: getData.address,
						propertyRight: getData.propertyOrgName,
						manageOrgName: getData.manageOrgName,
						parkLotType: `公共停车场合(${
							getData.parkLotType === 1 ? '室内' : getData.parkLotType === 2 ? '室外' : '信息错误'
						})`,
						parkLotLevel: `${getData.parkLevel === 0 ? '普通' : '特级'}`,
						parkLotCount: `规划车位数${getData.planParkCount}个 (已售车位${getData.saleParkCount}、经营车位数${
							getData.planParkCount + getData.saleParkCount
						}`,
						licenceIssuing: `重庆市${getData.districtName}城市管理局`,
						dateYear: date[0],
						dateMonth: date[1],
						dateDay: date[2],
					};
					setData(newData);
				}
			}
		});
	}, []);
	return (
		<div className={css.app}>
			<div className={css.content}>
				<p className={css.recordNo}>{data === undefined ? null : data.recordNo}</p>
				<p>{data === undefined ? null : data.name}</p>
				<p>{data === undefined ? null : data.address}</p>
				<p>{data === undefined ? null : data.propertyRight}</p>
				<p>{data === undefined ? null : data.manageOrgName}</p>
				<p>
					{data === undefined ? null : data.parkLotType}
					<span className={css.parkLotLevel}>{data === undefined ? null : data.parkLotLevel}</span>
				</p>
				<p>{data === undefined ? null : data.parkLotCount}</p>
				<div className={css.bottom}>
					<p>{data === undefined ? null : data.licenceIssuing}</p>
					<p>
						<span>{data === undefined ? null : data.dateYear}</span>
						<span style={{ marginLeft: '10px' }}>{data === undefined ? null : data.dateMonth}</span>
						<span style={{ marginLeft: '-8px' }}>{data === undefined ? null : data.dateDay}</span>
					</p>
				</div>
			</div>
		</div>
	);
}

export default Print;
